package edu.dayu.proxyTest3;

import java.util.ArrayList;
import java.util.List;

public class InterceptorChain {
    private List<Interceptor> interceptorList = new ArrayList<>();

    /**
     * 插入所有拦截器
     * 传入一个被代理的对象，然后用拦截器一层一层代理
     */
    public Object pluginAll(Object target) {
        for (Interceptor interceptor : interceptorList) {
            target = interceptor.plugin(target);
        }
        return target;
    }

    public void addInterceptor(Interceptor interceptor) {
        interceptorList.add(interceptor);
    }

}
